package com.huaxin.hxmodulesystem.controller;


import com.huaxin.hxmodulesystem.dto.ResponseResult;
import com.huaxin.hxmodulesystem.dto.request.AddSysDictionaryReqDTO;
import com.huaxin.hxmodulesystem.dto.request.UpdateSysDictionaryReqDTO;
import com.huaxin.hxmodulesystem.models.SysDictionary;
import com.huaxin.hxmodulesystem.service.SysDictionaryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "系统字典")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/sys/sysDict")
public class SystemDictController {

    private final SysDictionaryService systemDictService;

    //添加字典
    @Operation(summary = "添加字典", description = "添加供应商")
    @PostMapping("/addSysDict")
    public ResponseResult<Boolean> addSystemDict(@RequestBody AddSysDictionaryReqDTO in) {
        return systemDictService.addSystemDict(in);
    }

    //修改字典
    @Operation(summary = "修改字典", description = "修改字典")
    @PostMapping("/updateSysDict")
    public ResponseResult<Boolean> updateSystemDict(@RequestBody UpdateSysDictionaryReqDTO in) {
        return systemDictService.updateSystemDict(in);
    }

    //删除字典
    @Operation(summary = "删除字典", description = "删除字典")
    @GetMapping("/deleteSysDict")
    public ResponseResult<Boolean> deleteSystemDict(@Parameter(description = "字典Key", name = "dictKey") @RequestParam(name = "dictKey") String dictKey) {
        return systemDictService.deleteSystemDict(dictKey);
    }

    //查询字典
    @Operation(summary = "查询字典", description = "查询字典")
    @GetMapping("/querySysDict")
    public ResponseResult<List<SysDictionary>> querySystemDict(@Parameter(description = "字典类型", name = "dictType") @RequestParam(required = false, name = "dictType") String dictType) {
        return systemDictService.querySystemDict(dictType);
    }

    //根据key查询字典数据
    @Operation(summary = "根据key查询字典数据", description = "根据key查询字典数据")
    @GetMapping("/querySysDictByKey")
    public ResponseResult<SysDictionary> querySystemDictByKey(@Parameter(description = "字典key", name = "dictKey") @RequestParam(name = "dictKey", required = true) String dictKey) {
        return ResponseResult.ok(systemDictService.querySystemDictByKey(dictKey));
    }
}
